Repository navigation
Conversation
Macbet
left a comment
There was a problem hiding this comment.
The 404 check runs before any DB work and the property binding is fine. The main problem is the UPDATE guard, which blocks every save of a not-yet-migrated webhook once the flag is on. Details inline.
| switch (phase) { | ||
| case PRECOMMIT: | ||
| try { | ||
| if (isWebhookV1Disabled() && isSharedWebhookProvider(elideEntity) |
There was a problem hiding this comment.
This guard only looks at the new value (!elideEntity.isMigratedV2()), not at whether the value actually changed from true to false. The hook runs for any UPDATE of the webhook, and the UI save always sends an update op for it (with the events relationship).
So with WebhookV1Disabled=true, a workspace whose webhook is still migratedV2=false cannot save anything: editing a trigger branch fails with 400 "switching to webhook v1 is not allowed", which is also a misleading message for that case.
Suggestion: reject only when the original value was true and the new one is false (changes.get().getOriginal() for migratedV2, or the persisted row), and let untouched v1 rows through.
There was a problem hiding this comment.
Fixed in 75956322f — moved the revert guard to a field-level PRECOMMIT hook (WebhookV1RevertGuardHook) bound directly to Webhook.migratedV2 (UPDATE). It inspects ChangeSpec so only true -> false transitions are rejected with HTTP 400, allowing trigger edits and other updates on untouched migratedV2=false rows to pass.
| } | ||
|
|
||
| @Test | ||
| void execute_update_whenV1Disabled_rejectsRevertToV1() { |
There was a problem hiding this comment.
This test passes Optional.empty() and an entity that is simply migratedV2=false, so it exercises "update that does not touch migratedV2" rather than a revert, and currently pins the behaviour described on the guard. It would be good to have two cases: true -> false is rejected, and an update of an existing v1 row that leaves migratedV2 alone is accepted.
There was a problem hiding this comment.
Updated in 75956322f — added WebhookV1RevertGuardHookTest covering true -> false (rejected with 400), untouched false -> false / Optional.empty() (allowed), and v1.disabled=false (allowed), updated WebhookLifeCycleHookBindingTest for the field-level binding, and updated WebhookManageHookTest to verify untouched migratedV2=false updates succeed.
| ...(!webhookId && createShared && { attributes: { migratedV2: true } }), | ||
| ...(!webhookId && | ||
| vcsProvider && | ||
| SHARED_WEBHOOK_VCS.includes(vcsProvider) && { attributes: { migratedV2: true } }), |
There was a problem hiding this comment.
This is unconditional, while the flag defaults to false in this PR. SHARED_WEBHOOK_VCS covers every type except PUBLIC, so after this change the UI can no longer create a v1 webhook or switch back to one, even though the API still allows both. Is that intended as the new default for everyone regardless of the flag? If yes, worth stating in the PR description / release notes; if not, the UI needs to know the flag value.
There was a problem hiding this comment.
Yes, making the UI always create Webhook v2 for new setups (and removing the v2 -> v1 downgrade button) is intentional regardless of the flag. With #4064 adding Bitbucket Cloud v2 support, all supported webhook providers now work with v2, and once the full stack (#4064 + #4065 + #4066) is merged, #4066 enables v1.disabled=true by default and automatically migrates any remaining v1 workspaces on startup.
| io.terrakube.webhook.pr-base-branch-filter=${WebhookPrBaseBranchFilter:false} | ||
| # When true, the legacy per-workspace /webhook/v1/{webhookId} endpoint returns 404 | ||
| # and new webhooks for supported VCS providers are always created as shared v2 webhooks. | ||
| io.terrakube.webhook.v1.disabled=${WebhookV1Disabled:false} |
There was a problem hiding this comment.
Turning this on makes every existing v1 hook return 404 while the remote hooks stay registered, and nothing in this PR migrates them (that comes in #4066). Could the comment say that existing workspaces have to be migrated first? Also WebhookV1Disabled is not mentioned anywhere in the docs yet.
There was a problem hiding this comment.
Updated the application.properties comment in 75956322f to note that existing v1 workspaces must be migrated first (automated on startup in #4066 once the full stack is merged).
|
|
||
| @PostMapping("/webhook/v1/{webhookId}") | ||
| public ResponseEntity<String> processWebhook(@PathVariable String webhookId,@RequestBody Map<String, Object> payload,@RequestHeader Map<String, String> headers) { | ||
| if (webhookProperties != null && webhookProperties.getV1().isDisabled()) { |
There was a problem hiding this comment.
Nit: @RequestBody is still deserialized before this check, so a malformed body gets 400 instead of 404 when v1 is disabled. Not a problem functionally, just noting the endpoint still parses bodies.
There was a problem hiding this comment.
Acknowledged — keeping @RequestBody as-is since it does not affect valid webhook callers.
7878c86 to
7595632
Compare
|



Summary
Phase 2 of the stacked PR plan to deprecate Webhook v1 and standardize on shared repository webhooks (Webhook v2): introduces the
io.terrakube.webhook.v1.disabledproperty, enforces404/ v2-only creation on the API when enabled, and updates the UI so new setups exclusively create Webhook v2 and cannot revert v2 webhooks back to v1.Stack Overview
feat/webhook-v2-bitbucketmainfeat/webhook-v1-disable-flagfeat/webhook-v2-bitbucketio.terrakube.webhook.v1.disabledflag, 404/hook enforcement, UI v2-only creationfeat/webhook-v1-to-v2-startup-migrationfeat/webhook-v1-disable-flag@DisallowConcurrentExecutionQuartz migration job + defaultdisabled=trueChanges
application.properties,WebhookProperties):io.terrakube.webhook.v1.disabled=${WebhookV1Disabled:false}(webhookProperties.getV1().isDisabled()).WebHookController,WebhookManageHook):POST /webhook/v1/{webhookId}returns404 Not Foundimmediately whenv1.disabled=true.WebhookManageHookautomatically setsmigratedV2=trueonCREATEand rejectsUPDATEattempts revertingmigratedV2tofalsewith HTTP400whenv1.disabled=true.Webhook.tsx):migratedV2: true.WebHookControllerTestandWebhookV1DisabledIntegrationTest.WebhookManageHookTestandWebhook.test.tsx.Verification
WebHookControllerTest,WebhookManageHookTest,WebhookEventManageHookTest,WebhookServiceTest,RepoWebhookServiceTest,BitBucketWebhookServiceTest): 141 tests passed (0 failures, 0 errors).WebhookV1DisabledIntegrationTest,WebhookV1MigratedSecurityIntegrationTest,WebhookTests): 13 tests passed (0 failures, 0 errors).Webhook.test.tsx: 27/27 passed;lint:check: 0 errors;format:check&typecheck: passed).